package com.khshop.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.khshop.pojo.Menupriv;
import com.khshop.service.MenuprivService;
import com.khshop.vo.AjaxResult;
import com.khshop.vo.ServiceResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 按钮权限 前端控制器
 * </p>
 *
 * @author zhaoyang
 * @since 2020-10-16
 */
@Api(tags = "按钮权限 前端控制器")
@RestController
@RequestMapping("/")
public class MenuprivController {

    @Autowired
    MenuprivService menuprivService;

    //新增按钮权限
    @ApiOperation("新增按钮权限")
    @PostMapping("/addMenupriv")
    @ResponseBody
    public AjaxResult addMenupriv(@RequestBody Menupriv menupriv) {
        if (menuprivService.addMenupriv(menupriv).isFlag()) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }

    }

    //修改按钮权限
    @ApiOperation("修改按钮权限")
    @PostMapping("/updateMenupriv")
    @ResponseBody
    public AjaxResult updateMenupriv(@RequestBody Menupriv menupriv) {
        if (menuprivService.updateMenupriv(menupriv).isFlag()) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }

    }

    //删除按钮权限
    @ApiOperation("删除按钮权限")
    @PostMapping("/delMenupriv")
    @ResponseBody
    public AjaxResult delMenupriv(Integer id) {
        if (menuprivService.delMenupriv(id).isFlag()) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }

    }

    //查询按钮权限
    @ApiOperation("查询按钮权限")
    @PostMapping("/searchMenupriv")
    @ResponseBody
    public AjaxResult searchMenupriv(@RequestBody Map<String, String> map,
                                    @RequestParam(value = "page", defaultValue = "1") Integer page,
                                    @RequestParam(value = "limit", defaultValue = "15") Integer limit) {

        ServiceResult<IPage<Menupriv>> serviceResult = menuprivService.searchMenupriv(map, page, limit);
        if (serviceResult.isFlag()) {
            return AjaxResult.success((int) serviceResult.getData().getTotal(), serviceResult.getData());
        } else {
            return AjaxResult.error();
        }

    }
}

